/**
 * Created by heht on 2017/3/27.
 */
import Vue from 'vue'
import Vuex from 'vuex'
import createLogger from 'vuex/dist/logger'
import ModuleTeam from 'components/teamGame/store'
import * as actions from 'store/actions'
import * as getters from 'store/getters'
Vue.use(Vuex)

const state = {
  historyLength: 0,// 历史记录
  tip: {//提示框
    text: '',
    time: 1800,
    callback: null
  },
  modal:{//弹窗
    visible: false,
    modalId: '',
    callback: null
  },
  loading:{//loading
    visible: false,
    callback: null
  },
  guideParam:{
    guideType:''
  },
  initmoney: 0,  //创建组合-组合初始资金
  groupName: '',  //创建组合-组合名称
  addStocks: [],  //创建组合-添加至组合中的股票
  groupMessages: {  //创建组合信息
    tradeType: '',
    group: [],
    group_name: '',
    group_id: '',
    entrust_no: ''
  },
  myReasons: [],  //创建组合-选择模拟买入原因
  group_nickname: '',  //组合创建者的昵称
  buyDelegatePrice: '',
  buyStockCode: '',
  buyStockGroups: [],
  buyEnableVol: 0,
  buyAmount: 0,
  buyFivePrices: {},
  sellDelegatePrice: '',
  sellStockCode: '',
  sellStockGroups: [],
  sellEnableVol: 0,
  sellAmount: 0,
  sellFivePrices: {},
  buyStockName: '',
  sellStockName: '',
  buyStockMarket: '',
  sellStockMarket: '',
  buyReasons: [],
  sellReasons: [],
  buyDelegateType: '',
  sellDelegateType: '',
  buyGroupId: '',
  sellGroupId: '',
  sellSearchResultsVisible: false,
  buySearchResultsVisible: false,
  emojiVisible: false,
  gameTab: 0, // 显示团队PK(0)还是个人PK(1),
  teamFilters: null,// 团队赛列表过滤条件集合
  htmlHeight: 667 //页面高度
}

const mutations = {
  //提示框
  SET_TIP(state,tip){
    state.tip = tip
  },
  SET_MODAL(state,modal){
    state.modal = modal
  },
  SET_LOADING(state,loading){
    state.loading = loading
  },
  SET_GUIDE(state,guideParam){
    state.guideParam = guideParam;
  },
  //创建组合-组合初始资金
  SET_INITMONEY(state,initmoney){
    state.initmoney = initmoney
  },
  //创建组合-组合名称
  SET_GROUPNAME(state,groupName){
    state.groupName = groupName
  },
  //创建组合-添加至组合中的股票
  SET_ADDSTOCKS(state,addStocks){
    state.addStocks = addStocks
  },
  //创建组合信息
  SET_GROUPMESSAGES(state,groupMessages){
    state.groupMessages = groupMessages
  },
  //创建组合-选择模拟买入原因
  SET_MYREASONS(state,myReasons){
    state.myReasons = myReasons
  },
  //组合创建者的昵称
  SET_GROUPNICKNAME(state,group_nickname){
    state.group_nickname = group_nickname
  },
  // 设置买入委托价格
  SET_BUY_DELEGATE_PRICE(state, price) {
    state.buyDelegatePrice = price
  },
  // 买入股票代码
  SET_BUY_STOCK_CODE(state, code) {
    state.buyStockCode = code
  },
  // 设置买入股票组
  SET_BUY_STOCK_GROUPS(state, groups) {
    state.buyStockGroups = groups
  },
  // 设置买入最大数量
  SET_BUY_ENABLE_VOL(state, vol) {
    state.buyEnableVol = vol
  },
  // 设置购买数量
  SET_BUY_AMOUNT(state, amount) {
    state.buyAmount = amount
  },
  // 设置买入5档详情
  SET_BUY_FIVE_PRICES(state, prices) {
    state.buyFivePrices = prices
  },
  SET_SELL_STOCK_CODE(state, code) {
    state.sellStockCode = code
  },
  SET_SELL_STOCK_GROUPS(state, groups) {
    state.sellStockGroups = groups
  },
  SET_SELL_ENABLE_VOL(state, vol) {
    state.sellEnableVol = vol
  },
  SET_SELL_DELEGATE_PRICE(state, price) {
    state.sellDelegatePrice = price
  },
  SET_SELL_AMOUNT(state, amount) {
    state.sellAmount = amount
  },
  SET_SELL_FIVE_PRICES(state, prices) {
    state.sellFivePrices = prices
  },
  SET_BUY_STOCK_NAME(state, name) {
    state.buyStockName = name
  },
  SET_SELL_STOCK_NAME(state, name) {
    state.sellStockName = name
  },
  SET_BUY_STOCK_MARKET(state, market) {
    state.buyStockMarket = market
  },
  SET_SELL_STOCK_MARKET(state, market) {
    state.sellStockMarket = market
  },
  SET_BUY_REASONS(state, reasons) {
    state.buyReasons = reasons
  },
  SET_SELL_REASONS(state, reasons) {
    state.sellReasons = reasons
  },
  SET_BUY_DELEGATE_TYPE(state, delegateType) {
    state.buyDelegateType = delegateType
  },
  SET_SELL_DELEGATE_TYPE(state, delegateType) {
    state.sellDelegateType = delegateType
  },
  SET_BUY_GROUP_ID(state, groupId) {
    state.buyGroupId = groupId
  },
  SET_SELL_GROUP_ID(state, groupId) {
    state.sellGroupId = groupId
  },
  SET_SELL_SEARCH_RESULTS_VISIBLE(state, visible) {
    state.sellSearchResultsVisible = visible || false
  },
  SET_BUY_SEARCH_RESULTS_VISIBLE(state, visible) {
    state.buySearchResultsVisible = visible || false
  },
  SET_EMOJI_VISIBLE(state, visible) {
    state.emojiVisible = visible || false
  },
  //设置页面高度
  SET_HTML_HEIGHT(state, visible) {
    state.htmlHeight = visible
  },
  CLEAR_TRADE(state) {
    state.buyStockCode = ''
    state.buyStockMarket = ''
    state.buyStockName = ''
    state.buyEnableVol = 0
    state.buyGroupId = ''
    state.buyDelegatePrice = ''
    state.buyDelegateType = ''
    state.buyAmount = 0
    state.buyFivePrices = {}
    state.buyReasons = []

    state.sellStockCode = ''
    state.sellStockMarket = ''
    state.sellStockName = ''
    state.sellEnableVol = 0
    state.sellGroupId = ''
    state.sellDelegatePrice = ''
    state.sellDelegateType = ''
    state.sellAmount = 0
    state.sellFivePrices = {}
    state.sellReasons = []
  },
  ADD_HISTORY_LENGTH(state, len = 1) {
    state.historyLength = state.historyLength + len
  },
  HISTORY_BACK(state, len = 2) {
    state.historyLength = state.historyLength - len
  },
  SET_GAME_TAB(state, gameTab) {
    state.gameTab = gameTab
  },
  SET_TEAM_FILTERS(state, teamFilters) {
    state.teamFilters = teamFilters
  }
}

const modules = {
  team: ModuleTeam
}

export default new Vuex.Store({
  state,
  mutations,
  actions,
  getters,
  modules,
  plugins: [createLogger()]
})
